<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/resources/js/jquery-1.11.1.min.js"></script>
    <script src="/resources/js/self.js"></script>
    <script type="text/javascript" src="/resources/js/md5.js"></script>
</head>
<body>
<div class="row">
    <div class="col-md-12 col-sm-12 col-xs-12">
        <div class="x_panel">
            <div class="x_title">
                <h2>企业账户维护 <small></small></h2>
                <ul class="nav navbar-right panel_toolbox">

                    <li> <button onclick="back()" class="btn btn-primary" type="button">返回</button>
                    </li>
                </ul>
                <div class="clearfix"></div>
            </div>
            <div class="x_content">
                <br>
                <div id="demo-form2"  class="form-horizontal form-label-left" >
                    <input type="hidden" name="id" class="form-data" >
                    <input type="hidden" name="companyId" class="form-data" >
                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">名称 
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="text" id="name" name="name" 
                                   class="form-control form-data col-md-7 col-xs-12" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="account">账号 
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="text" id="account" name="account" 
                                   class="form-control form-data col-md-7 col-xs-12">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="password" class="control-label col-md-3 col-sm-3 col-xs-12">密码</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input id="password" name="password" class="form-control  col-md-7 col-xs-12" input="text"
                                   onfocus="this.type='password'" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">状态</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input style="width:15px;height:15px" type="radio" name="status" class="form-data" value="valid" /><span>开启</span>
                            <input style="width:15px;height:15px" type="radio" name="status" class="form-data" value="invalid"/><span>关闭</span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">描述 
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <textarea class="form-control form-data" name="desc" rows="3" placeholder=""></textarea>
                        </div>
                    </div>
                    <div class="ln_solid"></div>
                    <div class="form-group">
                        <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">

                            <button onclick="save()" class="btn btn-success">提交</button>
                            <!--<button onclick="back()" class="btn btn-primary" type="button">返回</button>-->
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    $(function () {
        setTitle("基本信息>企业信息>企业账户");
        initData();
    });

    function initData(){
        var data = getData();
        var companyId = data.companyId;
        if(null2empty(companyId) !==""){
            $("input[name='companyId']").val(companyId);
            $("input[name='password']").attr("placeholder","不修改密码不用填写");
            $.ajax({
                url:"/admin/companyUser/findByCompanyId.do",
                data:{'companyId':companyId},
                type:'post',
                dataType:'json',
                success:function(data){
                    console.log(data);
                    if(data.success){
                        initPageDate(data.data, '.form-data');
                        $("#oldPassword").val(data.data.password); //记录原密码
                        if(null2empty(data.data.id)!==""){
                            $("#account").attr('readonly','readonly');
                        }
                    }
                }
            });
        }

    }

    function save(){
        var params = getPageDataByClass("form-data");
        if(strIsNull(params['name'])) {
            alert("请输入企业账号名称");
            return;
        }
        if(strIsNull(params['account'])) {
            alert("请输入企业账号");
            return;
        }
        if(!strIsNull($("#password").val())) {
            params['password'] = hex_md5($("#password").val());
        }else if(strIsNull(params['id'])){
            alert("新建账号必须输入密码");
            return;
        }
        $.ajax({
            url:"/admin/companyUser/save.do",
            data:params,
            dataType:'json',
            type:'post',
            success:function(data){
                console.log(data);
                if(data.success){
                    alert("保存成功");
                    goto("company_list.html");
                }else{
                    alert(data.msg);
                }
            }
        });
    }
    function back() {
        goto("company_list.html");
    }
</script>
</html>